%option noyywrap

%{
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define YY_DECL int yylex()

#include "dgx.tab.h"

%}

%%

[ \t]	; // ignore all whitespace
0[1-7][0-7]*		{printf("INT8 %lu\n", strtoul(yytext, NULL, 8)); yylval.ival = strtoul(yytext, NULL, 8); return T_INT8;}
0x[0-9a-f][0-9a-f]*		{printf("INT16 %lu\n", strtoul(yytext, NULL, 16)); yylval.ival = strtoul(yytext, NULL, 16); return T_INT16;}
[0-9]+\.[0-9]+ 	{printf("FLOAT %f\n", atof(yytext)); yylval.fval = atof(yytext); return T_FLOAT;}
[0-9]+		{printf("INT10 %d\n", atoi(yytext)); yylval.ival = atoi(yytext); return T_INT10;}
\n		{return T_NEWLINE;}

"+"		{printf("PLUS\n"); return T_PLUS;}
"-"		{printf("MINUS\n"); return T_MINUS;}
"*"		{printf("MULTIPLY\n"); return T_MULTIPLY;}
"/"		{printf("DIVIDE\n"); return T_DIVIDE;}
">"		{printf("GT\n"); return T_GT;}
"<"		{printf("LT\n"); return T_LT;}
"="		{printf("EQ\n"); return T_EQ;}
"("		{printf("LEFT\n"); return T_LEFT;}
")"		{printf("RIGHT\n"); return T_RIGHT;}
"{"		{printf("LEFT_BR\n"); return T_LEFT_BR;}
"}"		{printf("RIGHT_BR\n"); return T_RIGHT_BR;}
";"		{printf("SEMI\n"); return T_SEMI;}


"if"		{printf("IF\n"); return T_IF;}
"then"		{printf("THEN\n"); return T_THEN;}
"else"		{printf("ELSE\n"); return T_ELSE;}
"while"		{printf("WHILE\n"); return T_WHILE;}
"do"		{printf("DO\n"); return T_DO;}

[a-z][0-9a-z]*		{printf("IDENT %s\n", yytext); yylval.name = yytext; return T_IDENT;}

%%

int main2()
{
	yyin = stdin;

	do {
		yylex();
	} while(!feof(yyin));

    return 0;
}